;;;;;;;;;;;;;;;;;;;;  additional plugins   ;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;  org basic setting  ;;;;;;;;;;;;;;;;;;;;
(setq org-file-apps (quote (("\\.pptx\\'" . system) ("\\.ppt\\'" . system) ("\\.xlsx\\'" . system) ("\\.xls\\'" . system) ("\\.docx\\'" . system) ("\\.doc\\'" . system) ("\\.odc\\'" . system) ("\\.odf\\'" . system) ("\\.odi\\'" . system) ("\\.otp\\'" . system) ("\\.odp\\'" . system) ("\\.otg\\'" . system) ("\\.odg\\'" . system) ("\\.ots\\'" . system) ("\\.ods\\'" . system) ("\\.odm\\'" . system) ("\\.ott\\'" . system) ("\\.odt\\'" . "soffice %s") (auto-mode . emacs) ("\\.mm\\'" . default) ("\\.x?html?\\'" . "chromium --enable-plugins %s") ("\\.pdf\\'" . "acroread %s"))))
(add-hook 'org-mode-hook '(lambda ()
                            (progn (org-cdlatex-mode)
                                   (company-mode)
                                   (outline-minor-mode)
                                   (flyspell-mode))))
(setq org-fontify-done-headline t)
(setq org-todo-keywords
      '((type "TODO" "STARTED" "WAITING" "DELEGATED" "|" "DONE" "CANCELED")));; Custom keywords
(setq safe-local-variable-values (quote ((after-save-hook archive-done-tasks))))
(setq org-startup-with-icons-mode t)
(setq org-modules (quote (org-bbdb org-bibtex org-crypt org-ctags org-docview org-gnus org-id org-info org-jsinfo org-habit org-inlinetask org-irc org-mac-message org-mew org-mhe org-protocol org-rmail org-special-blocks org-vm org-wl org-w3m org-mouse org-taskjuggler org-annotate-file org-bookmark org-checklist org-choose org-collector org-depend org-elisp-symbol org-eval org-eval-light org-expiry org-exp-bibtex org-git-link org-interactive-query org-invoice org-jira org-learn org-mairix org-mac-iCal org-mac-link-grabber org-man org-mtags org-odt org-panel org-registry org-screen org-secretary orgtbl-sqlinsert org-toc org-track org-velocity org-wikinodes)))

;;;;;;;;;;;;;;;;;;;;  remeber setting  ;;;;;;;;;;;;;;;;;;;;
(require 'remember)
(org-remember-insinuate)
(define-key global-map "\C-cr" 'org-remember)
(setq org-agenda-files emax-org-file)
(setq org-default-notes-file emax-remember-file)
(setq remember-all-handler-functions t)
(setq remember-handler-functions
      '(org-remember-handler
        (lambda nil
          (let* ((frame-names-alist (make-frame-names-alist))
                 (frame (cdr (assoc "*Remember*" frame-names-alist))))
            (if frame
                (delete-frame frame t))))))
(defun my-remember nil
  (progn (select-frame
          (make-frame '((name . "*Remember*") )))
         (raise-frame)
         (remember)))

;;;;;;;;;;;;;;;;;;;;  org babel setting  ;;;;;;;;;;;;;;;;;;;;
(require 'ob-R)
(org-babel-do-load-languages
 'org-babel-load-languages
 '((R . t)
   (ditaa . t)
   (dot . t)
   (emacs-lisp . t)
   (gnuplot . t)
   (haskell . nil)
   (ocaml . nil)
   (python . t)
   (ruby . t)
   (screen . nil)
   (sh . t)
   (C . t)
   (sql . nil)
   (sqlite . t)))
(unless (boundp 'org-babel-default-header-args:sh)
  (setq org-babel-default-header-args:sh '()))
(add-to-list 'org-babel-default-header-args:sh
             '(:shebang . "#!/bin/bash"))
(setq org-confirm-babel-evaluate nil)
(setq org-babel-no-eval-on-ctrl-c-ctrl-c t)

;;;;;;;;;;;;;;;;;;;;  org export setting  ;;;;;;;;;;;;;;;;;;;;
(setq org-export-html-style-include-default nil)
(setq org-export-htmlize-output-type 'css)
(setq org-export-html-link-home "/")
(setq org-export-latex-listings t)
(setq org-export-with-LaTeX-fragments t)
(setq org-export-latex-tables-column-borders t)
(setq org-export-latex-default-packages-alist '(("" "fixltx2e" t) ("" "graphicx" t) ("" "longtable" t) ("" "float" t) ("" "wrapfig" t) ("" "soul" t) ("" "textcomp" t) ("" "marvosym" t) ("" "wasysym" t) ("" "latexsym" t) ("" "amsmath" t) ("" "amsfonts" t) ("" "ifthen" t) ("" "hyperref" t) ("" "mypgf" t)))
(setq org-latex-to-pdf-process (quote ("xelatex -interaction nonstopmode -output-directory %o %f")))
(setq org-export-odt-styles-file "/zleinter/emax/org/contrib/odt/styles/styles.xml")
(setq org-combined-agenda-icalendar-file "/scratch/personal/org/test.ics")
(setq org-format-latex-options (quote (:foreground "black" :background "white" :scale 1.0 :html-foreground "black" :html-background "white" :html-scale 1.0 :matchers ("begin" "$1" "$" "$$" "\\(" "\\["))))
(setq org-export-html-style "<link rel=\"stylesheet\" href=\"/static/style.css\"  type=\"text/css\" /><script type=\"text/javascript\" src=\"/static/tablecloth.js\"></script>
<script type=\"text/javascript\">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-24351801-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>")

(setq org-export-latex-classes (quote (("article" "\\documentclass[11pt,a4paper]{article}
%\\usepackage[utf8]{inputenc}
\\usepackage[T1]{fontenc}
\\usepackage{ezfontcfg}
\\usepackage[version=3]{mhchem}
\\usepackage[colorlinks=true,bookmarksnumbered=true,linkcolor=blue,pdfstartview=FitH]{hyperref}
\\newcounter{note}
\\newcommand{\\note}[1]{
   \\refstepcounter{note}\\mbox{\\textsuperscript{\\tiny[\\thenote]}}
\\marginpar[\\raggedleft\\mbox{\\tiny\\textsuperscript{\\thenote}}\\parbox{\\marginparwidth}{\\rmfamily\\scriptsize\\color{red}#1}]
{\\raggedright\\mbox{\\tiny\\textsuperscript{\\thenote}}\\parbox{\\marginparwidth}{\\rmfamily\\scriptsize\\color{red}#1}}}
\\newcommand{\\nnote}[1]{
\\marginpar[\\raggedleft\\parbox{\\marginparwidth}{\\rmfamily\\scriptsize\\color{red}#1}]
{\\raggedright\\parbox{\\marginparwidth}{\\rmfamily\\scriptsize\\color{red}#1}}}
" ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}") ("\\paragraph{%s}" . "\\paragraph*{%s}") ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
                                       ("book" "\\documentclass[11pt]{book}
%\\usepackage[utf8]{inputenc}
\\usepackage[T1]{fontenc}
\\usepackage{ezfontcfg}
\\usepackage[colorlinks=true,bookmarksnumbered=true,linkcolor=blue,pdfstartview=FitH]{hyperref}
\\usepackage[version=3]{mhchem}
\\newcounter{note}
\\newcommand{\\note}[1]{
   \\refstepcounter{note}\\mbox{\\textsuperscript{\\tiny[\\thenote]}}
\\marginpar[\\raggedleft\\mbox{\\tiny\\textsuperscript{\\thenote}}\\parbox{\\marginparwidth}{\\rmfamily\\scriptsize\\color{red}#1}]
{\\raggedright\\mbox{\\tiny\\textsuperscript{\\thenote}}\\parbox{\\marginparwidth}{\\rmfamily\\scriptsize\\color{red}#1}}}
\\newcommand{\\nnote}[1]{
\\marginpar[\\raggedleft\\parbox{\\marginparwidth}{\\rmfamily\\scriptsize\\color{red}#1}]
{\\raggedright\\parbox{\\marginparwidth}{\\rmfamily\\scriptsize\\color{red}#1}}}" ("\\part{%s}" . "\\part*{%s}") ("\\chapter{%s}" . "\\chapter*{%s}") ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
                                       ("letter" "\\documentclass[11pt]{letter}
% \\usepackage[utf8]{inputenc}
\\usepackage[T1]{fontenc}
\\usepackage{lmodern}
\\usepackage{marvosym}
% \\usepackage{ngerman}
\\usepackage{ezfontcfg}
\\usepackage{graphicx}
\\pagestyle{empty}
\\usepackage[scale=0.775]{geometry}
\\setlength{\\parindent}{0pt}
\\addtolength{\\parskip}{6pt}
\\def\\firstname{Shulei}
\\def\\familyname{Zhu}
\\def\\FileAuthor{\\firstname \\familyname}
\\def\\FileTitle{\\firstname \\familyname's cover letter}
\\def\\FileSubject{Cover letter}
\\def\\FileKeyWords{\\firstname \\familyname, Cover letter}
\\renewcommand{\\ttdefault}{pcr}
\\usepackage{url}
\\urlstyle{tt}
% \\usepackage{geometry}
% \\geometry{a4paper,left=3cm,right=30mm, top=3cm, bottom=0cm} 
%\\setlength{\\oddsidemargin}{0.5cm}
%\\setlength{\\topmargin}{-1cm}
\\newcounter{note}
\\newcommand{\\note}[1]{
   \\refstepcounter{note}\\mbox{\\textsuperscript{\\tiny[\\thenote]}}
\\marginpar[\\raggedleft\\mbox{\\tiny\\textsuperscript{\\thenote}}\\parbox{\\marginparwidth}{\\rmfamily\\scriptsize\\color{red}#1}]
{\\raggedright\\mbox{\\tiny\\textsuperscript{\\thenote}}\\parbox{\\marginparwidth}{\\rmfamily\\scriptsize\\color{red}#1}}}
\\newcommand{\\nnote}[1]{
\\marginpar[\\raggedleft\\parbox{\\marginparwidth}{\\rmfamily\\scriptsize\\color{red}#1}]
{\\raggedright\\parbox{\\marginparwidth}{\\rmfamily\\scriptsize\\color{red}#1}}}
\\hypersetup{
pdfauthor = \\FileAuthor,%
pdftitle = \\FileTitle,%
pdfsubject = \\FileSubject,%
pdfkeywords = \\FileKeyWords,%
pdfcreator = \\LaTeX,%
pdfproducer = \\LaTeX}
" ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}") ("\\paragraph{%s}" . "\\paragraph*{%s}") ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
                                       ("report" "\\documentclass[11pt,a4paper]{report}
%\\usepackage[utf8]{inputenc}
\\usepackage[T1]{fontenc}
\\usepackage[x11names]{xcolor}
\\usepackage{ezfontcfg,booktabs, multirow, enumerate,tabularx,colortbl}
\\usepackage[version=3]{mhchem}
\\newcounter{note}
\\newcommand{\\note}[1]{
   \\refstepcounter{note}\\mbox{\\textsuperscript{\\tiny[\\thenote]}}
\\marginpar[\\raggedleft\\mbox{\\tiny\\textsuperscript{\\thenote}}\\parbox{\\marginparwidth}{\\rmfamily\\scriptsize\\color{red}#1}]
{\\raggedright\\mbox{\\tiny\\textsuperscript{\\thenote}}\\parbox{\\marginparwidth}{\\rmfamily\\scriptsize\\color{red}#1}}}
\\newcommand{\\nnote}[1]{
\\marginpar[\\raggedleft\\parbox{\\marginparwidth}{\\rmfamily\\scriptsize\\color{red}#1}]
{\\raggedright\\parbox{\\marginparwidth}{\\rmfamily\\scriptsize\\color{red}#1}}}
\\usepackage[colorlinks=true,bookmarksnumbered=true,linkcolor=blue,pdfstartview=FitH]{hyperref}" ("\\part{%s}" . "\\part*{%s}") ("\\chapter{%s}" . "\\chapter*{%s}") ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
                                       ("beamer" "
\\documentclass[english,10presentation]{beamer}
\\usepackage[english]{babel}
%\\usepackage[utf8]{inputenc}
\\usepackage[T1]{fontenc}
\\newcommand{\\annotation}[1]{%
  \\marginpar{\\ttfamily\\color{cyan}#1}}
\\mode<article>
{
  \\usepackage{times}
  \\usepackage{mathptmx}
  \\usepackage[left=1.5cm,right=6cm,top=1.5cm,bottom=3cm]{geometry}
}
\\usepackage{fancybox}
\\usepackage{multimedia}
\\usepackage{colortbl}
\\usepackage{yfonts}
\\usepackage{colortbl}
\\usepackage{translator}
\\usepackage{times}
\\usepackage{fixltx2e}
\\usepackage{graphicx}
\\usepackage{longtable}
\\usepackage{float}
\\usepackage{wrapfig}
\\usepackage{soul}
\\usepackage{textcomp}
\\usepackage{marvosym}
\\usepackage{wasysym}
\\usepackage{latexsym}
%\\usepackage{amssymb}
\\usepackage{amsmath}
\\usepackage{amsfonts}
\\usepackage{ifthen}
\\usepackage{mypgf}
\\usepackage{hyperref}
" org-beamer-sectioning))))


;;;;;;;;;;;;;;;;;;;;  org publish setting  ;;;;;;;;;;;;;;;;;;;;
(setq org-publish-project-alist
      '(("dimilar"
         :base-directory "/scratch/personal/org/index"
         :publishing-directory "/scratch/personal/org/myweb/"
         :base-extension "org"
         :recursive t
         :publishing-function org-publish-org-to-html
         :headline-levels 3
         :section-numbers nil
         :table-of-contents nil
         :auto-preamble t
         :auto-postamble t
         :auto-index t                  
         :index-filename "ind.org"
         :index-title "Dimilar's Website"
         :link-home "/index.php"
         )
        ("org-notes"
         :base-directory "/scratch/personal/org/blog"
         :publishing-directory "/scratch/personal/org/myweb/blog"
         :base-extension "org"
         :recursive t
         :publishing-function org-publish-org-to-html
         :headline-levels 3
         :section-numbers nil
         :table-of-contents nil
         :auto-preamble t
         :auto-postamble t
         :auto-index t                  
         :index-filename "index.org"
         :index-title "dimilar diary"
         :link-home "/index.php"
         )

        ("research"
         :base-directory "/scratch/personal/org/research"
         :publishing-directory "/scratch/personal/org/myweb/research"
         :base-extension "org"
         :recursive t
         :publishing-function org-publish-org-to-html
         :headline-levels 3
         :section-numbers nil
         :table-of-contents nil
         :auto-preamble t
         :auto-postamble t
         :auto-index t                  
         :index-filename "index.org"
         :index-title "dimilar factory"
         :link-home "/index.php"
         )
        
        ("contact"
         :base-directory "/scratch/personal/org/contact"
         :publishing-directory "/scratch/personal/org/myweb/contact"
         :base-extension "org"
         :recursive t
         :publishing-function org-publish-org-to-html
         :headline-levels 3
         :section-numbers nil
         :table-of-contents nil
         :auto-preamble t
         :auto-postamble t
         :auto-index t                  
         :index-filename "index.org"
         :index-title "Contact Information"
         :link-home "/index.php"
         )

        ("ics"
               :base-directory "/scratch/personal/org"
               :base-extension "ics"
               :publishing-directory "/ftp:adm8570@91.194.91.202:~/public_html/"
               :publishing-function org-publish-attachment)

        ("albums"
         :base-directory "/scratch/personal/org/albums"
         :publishing-directory "/scratch/personal/org/myweb/albums"
         :base-extension "org"
         :recursive t
         :publishing-function org-publish-org-to-html
         :headline-levels 3
         :section-numbers nil
         :table-of-contents nil
         :auto-preamble t
         :auto-postamble t
         :auto-index t                  
         :index-filename "index.org"
         :index-title "Photo Gallery"
         :link-home "/index.php"
         )

        ("projects"
         :base-directory "/scratch/personal/org/projects"
         :publishing-directory "/scratch/personal/org/myweb/projects"
         :base-extension "org"
         :recursive t
         :publishing-function org-publish-org-to-html
         :headline-levels 3
         :section-numbers nil
         :table-of-contents nil
         :auto-preamble t
         :auto-postamble t
         :auto-index t                  
         :index-filename "index.org"
         :index-title "My Projects"
         :link-home "/index.php"
         )
        
        ("download"
         :base-directory "/scratch/personal/org/download"
         :publishing-directory "/scratch/personal/org/myweb/download"
         :base-extension "org"
         :recursive t
         :publishing-function org-publish-org-to-html
         :headline-levels 3
         :section-numbers nil
         :table-of-contents nil
         :auto-preamble t
         :auto-postamble t
         :auto-index t                  
         :index-filename "index.org"
         :index-title "Download"
         :link-home "/index.php"
         )
        
        ("org-static"
         :base-directory "/scratch/personal/org/pdf"
         :publishing-directory "/scratch/personal/org/myweb/pdf"
         :recursive t
         :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|swf"
         :publishing-function org-publish-attachment)

        ("org" :components ("dimilar" "org-notes" "org-static" "research" "contact" "albums" "download"))))


(setq
 appt-message-warning-time 5
 appt-display-mode-line t
 appt-display-format 'window)
;; (appt-activate 1)
(display-time)
(add-hook 'org-finalize-agenda-hook 'org-agenda-to-appt)

;;;;;;;;;;;;;;;;;;;; org & google calendar synchronization  ;;;;;;;;;;;;;;;;;;;;
;;;;;please refer http://orgmode.org/worg/org-tutorials/org-google-sync.html;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; (setq org-export-exclude-category (list "google" "private"));;; define excluded categories
;; ;;; define filter. The filter is called on each entry in the agenda.
;; ;;; It defines a regexp to search for two timestamps, gets the start
;; ;;; and end point of the entry and does a regexp search. It also
;; ;;; checks if the category of the entry is in an exclude list and
;; ;;; returns either t or nil to skip or include the entry.
;; (defun org-mycal-export-limit ()
;;   "Limit the export to items that have a date, time and a range. Also exclude certain categories."
;;   (setq org-tst-regexp "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} ... [0-9]\\{2\\}:[0-9]\\{2\\}[^\r\n>]*?\
;; \)>")
;;   (setq org-tstr-regexp (concat org-tst-regexp "--?-?" org-tst-regexp))
;;   (save-excursion
;;     ; get categories
;;     (setq mycategory (org-get-category))
;;     ; get start and end of tree
;;     (org-back-to-heading t)
;;     (setq mystart    (point))
;;     (org-end-of-subtree)
;;     (setq myend      (point))
;;     (goto-char mystart)
;;     ; search for timerange
;;     (setq myresult (re-search-forward org-tstr-regexp myend t))
;;     ; search for categories to exclude
;;     (setq mycatp (member mycategory org-export-exclude-category))
;;     ; return t if ok, nil when not ok
;;     (if (and myresult (not mycatp)) t nil)))
;; ;;; activate filter and call export function
;; (defun org-mycal-export () 
;;   (let ((org-icalendar-verify-function 'org-mycal-export-limit))
;;     (org-export-icalendar-combine-agenda-files)))
;; (setq org-icalendar-use-scheduled '(todo-start event-if-todo))

;;;;;;;;;;;;;;;;;;;;  local keybind  ;;;;;;;;;;;;;;;;;;;;
(define-key org-mode-map "\C-c\C-p" 'org-set-property)
(define-key org-mode-map "\C-x\C-x" 'org-export-as-pdf)

;;;;;;;;;;;;;;;;;;;;  junk  ;;;;;;;;;;;;;;;;;;;;
;;(load "org-exp")
;;(load "org-latex")
;;(setq org-hide-leading-stars t)     ; only show one *
;;(require 'org-publish)
